# Minimal autoconf
AC_PREREQ(2.59c)

AC_INIT([starling], [20080318], [huntermorris@gmail.com])

AM_INIT_AUTOMAKE([dist-zip dist-bzip2 -Wall -Wno-portability])

# Sanity check
AC_CONFIG_SRCDIR(README)

# Check for strip
AC_CHECK_TOOL([STRIP], [strip])

# Subdirs
AC_PROG_MAKE_SET

# Check for basic compilation tools
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_MKDIR_P

# Do we have GCC or some other C compiler?
AM_CONDITIONAL(GCC, test "$GCC" = yes)

# Headers
AC_HEADER_STDBOOL
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([errno.h])
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([limits.h])
AC_CHECK_HEADERS([netdb.h])
AC_CHECK_HEADERS([netinet/in.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([string.h])
AC_CHECK_HEADERS([strings.h])
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([sys/types.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([sys/timeb.h])
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([zlib.h])

# C features
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE

# C types
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL

AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_INT8_T
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# C functions
AC_FUNC_ALLOCA
AC_FUNC_MEMCMP
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([ntohs])
AC_CHECK_FUNCS([htons])
AC_CHECK_FUNCS([ntohl])
AC_CHECK_FUNCS([htonl])
AC_CHECK_FUNCS([memset])
AC_CHECK_FUNCS([strchr])
AC_CHECK_FUNCS([strerror])
AC_CHECK_FUNCS([strrchr])
AC_CHECK_FUNCS([strstr])
AC_CHECK_FUNCS([strtol])
AC_CHECK_FUNCS([strtoul])
AC_CHECK_FUNCS([strtoll])
AC_CHECK_FUNCS([strtoull])
AC_CHECK_FUNCS([strtold])
AC_CHECK_FUNCS([strtod])
AC_CHECK_FUNCS([strtof])
AC_CHECK_FUNCS([strtold_l])
AC_CHECK_FUNCS([strtod_l])
AC_CHECK_FUNCS([strtof_l])
AC_CHECK_FUNCS([sprintf_l])
AC_CHECK_FUNCS([wctomb])
AC_CHECK_FUNCS([mbtowc])

# Enable debugging?
AX_DEBUG_CHECK

# Exporting .so files
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

# Erlang stuff
AC_ERLANG_SUBST_ROOT_DIR
AC_ERLANG_SUBST_LIB_DIR
AC_ERLANG_CHECK_LIB(erl_interface)
AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(starling, 1.0)

AX_ERLANG_SUBST_ERTS_DIR

# Dryverl
AX_DRYVERL

# Check for ICU and define appropriate flags
AX_ICU_CHECK([3.6])

# For lib dir in erlang
AC_SUBST(libdir)

AC_CONFIG_FILES([Makefile])

AC_OUTPUT
